package com.chenliang.invoke;

import com.alibaba.fastjson.JSON;
import com.chenliang.invoke.po.User;
import com.chenliang.invoke.utils.HttpClientUtils;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;

/**
 * @program: springboot_all
 * @description:
 * @author: liangchen23
 * @create: 2022-03-16 10:51
 */
public class InvokeDemo {


    public static void main(String[] args) {
        //@PostMapping("/get1")=>(String id) ,参数直接拼接id在url后面
        MultiValueMap<String, String> paramMap = new LinkedMultiValueMap<>();
        String url1 = "http://127.0.0.1:8081/user/get1?id=2";
        System.out.println(HttpClientUtils.doPostForm(url1, paramMap, String.class));

        //@PostMapping("/get1")=>(String id) ,参数放在body的from-data
        String url = "http://127.0.0.1:8081/user/get1";
        MultiValueMap<String, String> paramMap1 = new LinkedMultiValueMap<>();
        paramMap1.add("id","1");
        System.out.println(HttpClientUtils.doPostForm(url, paramMap1, String.class));


        //@PostMapping("/get2") ( User user)
        String url2 = "http://127.0.0.1:8081/user/get2";
        MultiValueMap<String, String> paramMap2 = new LinkedMultiValueMap<>();
        paramMap2.add("id","2");
        paramMap2.add("name","2");
        System.out.println(HttpClientUtils.doPostForm(url2, paramMap2, String.class));

        //@PostMapping("/get3") (@RequestBody User user)
        String url3 = "http://127.0.0.1:8081/user/get3";
        User user = new User();
        user.setId("id");
        user.setName("name");
        String s = JSON.toJSONString(user);
        System.out.println(HttpClientUtils.doPostJson(url3, s, User.class));

    }
}
